// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import FColliderManager from "./collider-system/FColliderManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    private nodeCount: number = 2000;
    @property(cc.Prefab)
    testPrefab: cc.Prefab = null;
    private pool: cc.NodePool = null;
    start() {
        FColliderManager.instance.enable = true;
        // FColliderManager.instance.enableQuadTreeDraw = true;
        // FColliderManager.instance.enableDebugDraw = true;
        this.pool = new cc.NodePool();
        for (let i = 0; i < this.nodeCount; i++) {
            this.createNode();
        }
    }
    private _list: cc.Node[] = [];
    createNode() {
        let node = this.pool.get();
        if (!node) node = cc.instantiate(this.testPrefab);
        node.parent = this.node;
        node.setPosition(this.getRandomPos());
        node.color = cc.Color.WHITE;
        this.runAction(node);
        this._list.push(node);
    }

    private getRandomPos() {
        return cc.v2(cc.winSize.width * Math.random() - cc.winSize.width * 0.5, cc.winSize.height * Math.random() - cc.winSize.height * 0.5);
    }

    private runAction(node) {
        cc.tween(node).to(3 * Math.random() + 3, {
            position: this.getRandomPos()
        }).call(() => {
            this.runAction(node);
        }).start();
    }
    // update (dt) {}
}
